const http = require("node:http");

// get请求
// const options = {
//     hostname: 'www.baidu.com',
//     timeout: 5000
// }

// post请求 13212
const postData = JSON.stringify({
    is_sms: 0,
    password: "Asdf1234.",
    phone: "13212341234",
    plat: "pc"
})
const options = {
    hostname: '297414r6j8.picp.vip',
    path: '/v6/login',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(postData) // 这里是buffer长度
    }
}
const clientRequest = http.request(options, function (res) {
    const chunks = []
    res.on('data', (chunk) => {
        chunks.push(chunk.toString('utf-8'))
    })

    res.on('end', () => {
        console.log(chunks.join(''))
    })
})
clientRequest.on('finish', () => {
    console.log('finish')
})
clientRequest.on('connect', () => {
    console.log('connect')
})

clientRequest.on('response', () => {
    console.log('response')
})

clientRequest.on('information', () => {
    console.log('information')
})
clientRequest.on('timeout', () => {
    console.log('timeout')
})
clientRequest.write(postData)
clientRequest.end()

// 正常的请求事件顺序 finish res response

// 超时  timeout
